<?php
    include('header.php');
    include('submenu.php');
    
    $sql = 'SELECT * FROM subscribe ORDER BY s_id';
    $result = $db->Execute($sql);
    if($result->RecordCount()>0){
        $emailfile = ADMINPATH.'/files/subscribe.csv';
        $objWrite = fopen($emailfile, "w");
                
        if($objWrite){
            fwrite($objWrite, "\"No.\",\"Email\" \n");
            $i = 1;
            while (!$result->EOF){
                fwrite($objWrite, "\"".($i++)."\",\"".$result->fields['s_email']."\" \n");
                $result->MoveNext();
            }
            $result->Close();
            fclose($objWrite);
            $msg = '<button class="button" onclick="window.location=\'?m=subscribe&s=download_subscribe\'">Export</button>';
        }else{
            $msg = 'Can\'t open file (docs/subscribe.csv).';
        }
    }else{
        $msg = 'ยังไม่มีข้อมูลสมาชิกที่สมัครรับข่าวสาร.';
    }
?>
    <div class="grid_18" id="contents">
        
        <div id="contents_">
            <?php echo $msg; ?>
        </div>
        
    </div><!-- end .grid_18 -->
    <div class="clear">&nbsp;</div>
<?
    include('footer.php');
?>